package model.structs;

/**
 * A point representing a location in (x, y) coordinate space, specified in integer precision.
 *
 * @author rhaq
 * @version 1.00 2009-05-09 Initial submission.
 */
public class Point
{
	/** The x coordinate. */
	private int x;

	/** The y coordinate. */
	private int y;


	/**
	 * Constructs and initializes a point at the origin (0, 0) of the coordinate space.
	 */
	public Point()
	{
		this.x = 0;
		this.y = 0;
	}


	/**
	 * Constructs and initializes a point at the specified (x, y) location in the
	 * coordinate space.
	 * @param x The x-coordinate to set.
	 * @param y The y-coordinate to set.
	 */
	public Point(int x, int y)
	{
		setX(x);
		setY(y);
	}


	/**
	 * Decrements the x-coordinate by the specified amount.
	 * @param x The amount to decrement the x-coordinate by.
	 */
	public void decrementX(int x)
	{
		this.x -= x;
	}


	/**
	 * Decrements the x-coordinate by the specified amount.
	 * @param x The amount to decrement the x-coordinate by.
	 */
	public void decrementY(int y)
	{
		this.y -= y;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj)
	{
		boolean result = false;

		try {
			Point p = (Point)obj;
			result = (p.x == x) && (p.y == y);
		}

		catch (ClassCastException ce)
		{
		}

		return result;
	}


	/**
	 * Retrieves the x-coordinate of this point.
	 * @return The X coordinate of the point in integer precision.
	 */
	public int getX()
	{
		return x;
	}


	/**
	 * Retrieves the y-coordinate of this point.
	 * @return The Y coordinate of the point in integer precision.
	 */
	public int getY()
	{
		return y;
	}


	/**
	 * Increments the x-coordinate by the specified amount.
	 * @param x The amount to increment the x-coordinate by.
	 */
	public void incrementX(int x)
	{
		this.x += x;
	}


	/**
	 * Increments the x-coordinate by the specified amount.
	 * @param x The amount to increment the x-coordinate by.
	 */
	public void incrementY(int y)
	{
		this.y += y;
	}


	/**
	 * Resets the x-value to the origin.
	 */
	public void resetX()
	{
		this.x = 0;
	}


	/**
	 * Resets the y-value to the origin.
	 */
	public void resetY()
	{
		this.y = 0;
	}


	/**
	 * Changes the x-coordinate of this point to the specified location.
	 * @param x The new x-coordinate of this point.
	 */
	public void setX(int x)
	{
		this.x = x;
	}


	/**
	 * Changes the y-coordinate of this point to the specified location.
	 * @param y The new y-coordinate of this point.
	 */
	public void setY(int y)
	{
		this.y = y;
	}
}